import java.io.File;
import java.util.Scanner;

/**
 * 遍历文件夹中的文件
 * 
 * @author Zero
 */
public class TraverseFolder {
    public static void main(String[] args) {
        System.out.print("请输入绝对路径：");
        Scanner input = new Scanner(System.in);
        String path = input.nextLine();
        System.out.println("当前路径为：" + path);
        System.out.println("当前文件夹的文件有：");
        printFiles(new File(path), 0);
        input.close();
    }

    public static void printFiles(File f, int n) {
        if (f.isDirectory()) {
            File[] next = f.listFiles();
            for (int i = 0; i < next.length; i++) {
                for (int j = 0; j < n; j++) {
                    System.out.print("|~~");
                }
                System.out.println(next[i].getName());
                if (next[i].isDirectory()) {
                    printFiles(next[i], n + 1);
                }
            }
        } else {
            System.err.println("Error! This is not a folder! May be a file.");
        }
    }
}
